<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <a-form-item label="学号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['number']" placeholder="请输入学号" :disabled='true'></a-input>
        </a-form-item>
        <a-form-item label="姓名" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['name']" placeholder="请输入姓名" :disabled='true'></a-input>
        </a-form-item>
        <a-form-item label="性别" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['sex']" placeholder="请输入性别" :disabled='true'></a-input>
        </a-form-item>
        <a-form-item label="出生年月" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择出生年月" v-decorator="['birthday']" :trigger-change="true" style="width: 100%" :disabled='true'/>
        </a-form-item>
        <a-form-item label="民族" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['nation']" placeholder="请输入民族" :disabled='true'></a-input>
        </a-form-item>
        <a-form-item label="身份证" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['idCard']" placeholder="请输入身份证" :disabled='true'></a-input>
        </a-form-item>
        <a-form-item label="政治面貌" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['zzmm']" placeholder="请输入政治面貌" :disabled='true'></a-input>
        </a-form-item>
        <a-form-item label="家庭人口数" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['jtrks']" placeholder="请输入家庭人口数" :disabled='true'></a-input>
        </a-form-item>
        <a-form-item label="在校月开销" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['zxykx']" placeholder="请输入在校月开销" :disabled='true'></a-input>
        </a-form-item>
        <a-form-item label="是否建档立卡" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['sfjdlk']" placeholder="请输入是否建档立卡" :disabled='true'></a-input>
        </a-form-item>
        <a-form-item label="入学前户口" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['rxqhk']" placeholder="请输入入学前户口" :disabled='true'></a-input>
        </a-form-item>
        <a-form-item label="是否单亲" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['sfdq']" placeholder="请输入是否单亲" :disabled='true'></a-input>
        </a-form-item>
        <a-form-item label="是否孤残" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['sfgc']" placeholder="请输入是否孤残" :disabled='true'></a-input>
        </a-form-item>
        <a-form-item label="是否烈士或优抚对象子女" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['sflshyfdxzn']" placeholder="请输入是否烈士或优抚对象子女" :disabled='true'></a-input>
        </a-form-item>
        <a-form-item label="家庭人均年收入" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['jtrjnsr']" placeholder="请输入家庭人均年收入" :disabled='true'></a-input>
        </a-form-item>
        <a-form-item label="系别" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['depaerment']" placeholder="请输入系别" :disabled='true'></a-input>
        </a-form-item>
        <a-form-item label="专业" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['professor']" placeholder="请输入专业" :disabled='true'></a-input>
        </a-form-item>
        <a-form-item label="邮政编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['yzemail']" placeholder="请输入邮政编码":disabled='true'></a-input>
        </a-form-item>
        <a-form-item label="在校联系电话" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['phoneschool']" placeholder="请输入在校联系电话" :disabled='true'></a-input>
        </a-form-item>
        <a-form-item label="家庭成员情况" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['jtcyqk']" placeholder="请输入家庭成员情况" :disabled='true'></a-input>
        </a-form-item>
        <a-form-item label="影响家庭经济状况有关信息" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['yxjtjjzkygxx']" placeholder="请输入影响家庭经济状况有关信息" :disabled='true'></a-input>
        </a-form-item>
        <a-form-item label="学生陈述申请认定理由" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['ly']" placeholder="请输入学生陈述申请认定理由" :disabled='true'></a-input>
        </a-form-item>
        <a-form-item label="评议小组意见" :labelCol="labelCol" :wrapperCol="wrapperCol">
<!--          <a-input v-decorator="['pyxzyjString']" placeholder="请输入评议小组意见"></a-input>-->
          <a-upload
            action="https://www.mocky.io/v2/5cc8019d300000980a055e76"
            list-type="picture"
            :default-file-list="fileList"
            :disabled='true'
          >
          </a-upload>
        </a-form-item>
        <a-form-item label="签字" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-upload
            action="https://www.mocky.io/v2/5cc8019d300000980a055e76"
            list-type="picture"
            :default-file-list="fileList2"
            :disabled='true'
          >
          </a-upload>
        </a-form-item>

      </a-form>
    </a-spin>
  </j-modal>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import { validateDuplicateValue } from '@/utils/util'
  import JDate from '@/components/jeecg/JDate'  


  export default {
    name: "DiyPinkunModal",
    components: { 
      JDate,
    },
    data () {
      return {
        fileList:[],
        fileList2:[],
        form: this.$form.createForm(this),
        title:"操作",
        width:1000,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/pinkun/diyPinkun/add",
          edit: "/pinkun/diyPinkun/edit",
        }
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {

        let temp = record.pyxzyjString
        temp = temp.replaceAll("[","")
        temp = temp.replaceAll("]","")
        temp = temp.replaceAll("\"","")
        let imgString = temp.split(",")
        for (let i = 0; i < imgString.length; i++) {
          let param = {
            uid: i,
            name: i+'.png',
            status: 'done',
            url: imgString[i],
            thumbUrl: imgString[i],
          }

          this.fileList.push(param)
        }
        let param = {
          uid: 1,
          name: '签字.png',
          status: 'done',
          url: record.qzString,
          thumbUrl: record.qzString,
        }
        this.fileList2.push(param)


        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'number','name','sex','birthday','nation','idCard','zzmm','jtrks','zxykx','sfjdlk','rxqhk','sfdq','sfgc','sflshyfdxzn','jtrjnsr','depaerment','professor','yzemail','phoneschool','jtcyqk','yxjtjjzkygxx','ly','pyxzyjString','qzString'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }
         
        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'number','name','sex','birthday','nation','idCard','zzmm','jtrks','zxykx','sfjdlk','rxqhk','sfdq','sfgc','sflshyfdxzn','jtrjnsr','depaerment','professor','yzemail','phoneschool','jtcyqk','yxjtjjzkygxx','ly','pyxzyjString','qzString'))
      },

      
    }
  }
</script>